<?php
$user = new User();
$u = $_SERVER["REQUEST_URI"];
$u = explode('server?',$u);
if(!isset($u[1]))$u[1] = '/';
$error = '';
	
if(isset($_POST['r_submit'])){
	if($user->checkMail($_POST['r_mail']) && !$user->checkExits($_POST['r_mail']) && $_POST['yzm'] == $_SESSION['checkcode']){
		$sql = "select u_id from speed_user order by u_id desc limit 1";
		$id = $user->query($sql,'one');
		$u_id = $id['u_id']+1;
		$data = array("user_email" => $_POST['r_mail'],
							  "user_pwd" => md5($_POST['r_pwd']),
							  "u_id" => $u_id,
							  "create_time" => date("Y-m-d H:i:s",time()));
		if($user->addNewUser($data)){
			$user->login($_POST['r_mail'],md5($_POST['r_pwd']),$u[1]);
		}else echo "<script type='text/javascript'>alert('未知错误');</script>";
	}else $error = "信息填写错误";
}

if(isset($_POST['login_submit'])){
	if($user->checkUserLogin($_POST['u_mail'],$_POST['u_pwd']))echo "<script type='text/javascript'>location.href='$u[1]';</script>";
	else $error = "用户名或密码错误";
}


echo $error;
?>